Option Strict Off
Option Explicit On
Module Emulator
	Public Structure c_requestBit
		Dim Bit() As Byte
		Dim value As Double
		Dim Mult As Double
		Dim Add As Double
		Dim Update As Boolean
	End Structure
	
	Public Structure m_consultLog
		Dim RPM As Integer
		Dim Afm As Integer
		Dim Temp As Byte
		Dim Inj As Double
		Dim Ign As Byte
		Dim TP As Integer
		Dim o2 As Integer
		Dim rafm As Integer
		Dim Rinj As Double
		Dim Ro2 As Integer
		Dim Vbat As Integer
		Dim Spd As Short
		Dim AAC As Byte
		Dim Reg1 As Byte
		Dim Reg2 As Byte
	End Structure
	
	'UPGRADE_WARNING: Arrays in structure c_InjectorLh may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_InjectorLh As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_InjectorRh may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_InjectorRh As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_RPM may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_RPM As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_afmRh may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_afmRh As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_afmLh may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_afmLh As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_coolant may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_coolant As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_o2sensorLh may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_o2sensorLh As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_o2sensorRh may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_o2sensorRh As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_speed may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_speed As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_voltage may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_voltage As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_tps may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_tps As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_exhaustTemp may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_exhaustTemp As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_digitalReg1 may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_digitalReg1 As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_digitalReg2 may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_digitalReg2 As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_ignition may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_ignition As c_requestBit
	'UPGRADE_WARNING: Arrays in structure c_aac may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
	Public c_aac As c_requestBit
	
	'UPGRADE_WARNING: Lower bound of array Col was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
	Public Col(16) As Boolean
	'UPGRADE_WARNING: Lower bound of array Row was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
	Public Row(16) As Boolean
	
	
    Public Function Init_Off() As Boolean
        If CBool(MR_CheckIntrumentConnection) = True Then
            Call Err_message("Connection Not Present")
        Else
            frmMain.tmrTrace.Enabled = False
            MR_TraceStop()
            MR_EmulationStop()
            MR_LedSetMode(multiROM.MR_LedModeT.MR_LED_BLINK_SLOW)
            Call Status_running(False)
            Call Err_message("Emulator Off")
            'UPGRADE_WARNING: Couldn't resolve default property of object m_live. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            m_live = False
        End If
        Init_Off = True
    End Function
	
    Public Function Init_On() As Boolean
        Dim codee As Byte
        If CBool(MR_CheckIntrumentConnection) = True Then
            Call Err_message("Connection Not Present")
        Else
            'UPGRADE_WARNING: Couldn't resolve default property of object m_traceStart. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            If CBool(MR_TraceSetRange(m_traceStart, m_traceEnd)) = False Then
                codee = MR_GetError()
                Call Err_message("ERR" & Str(codee))
                Exit Function
            End If
            If CBool(MR_EmulationStart()) = False Then
                codee = MR_GetError()
                Call Err_message("ERR" & Str(codee))
                Init_On = False
            Else
                MR_LedSetMode(multiROM.MR_LedModeT.MR_LED_BLINK_FAST)
                Call Status_running(True)
                Call Err_message("Emulator On")
                'UPGRADE_WARNING: Couldn't resolve default property of object m_live. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                m_live = True
                Init_On = True
            End If
        End If
    End Function
	
    Public Function Init_Test(ByRef DummyArgument As Object) As Boolean
        'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
        Call frmMain.Init_Emulator(System.DBNull.Value)
        If MR_PodTestIO(m_callback) Then
            Call Err_message("Test All A-OK!")
            Init_Test = True
        Else
            Call Err_message("Test Failed!")
            Init_Test = False
        End If

    End Function
	
	
    Public Function m_emuTraceBuffer_show(ByRef red As Short, ByRef green As Short, ByRef blue As Short) As Boolean
        If frmMain.Fuel.Enabled = True Then
            Call m_emuTraceBuffer_display((frmMain.Fuel), red, green, blue)
        End If
        m_emuTraceBuffer_show = True
    End Function
	
	Private Function m_emuTraceBuffer_display(ByRef Grid As AxMSFlexGridLib.AxMSFlexGrid, ByRef red As Short, ByRef green As Short, ByRef blue As Short) As Object
		Dim i As Object
		Dim x As Byte ' show the trace buffer
		With Grid
			'.Redraw = False
			For i = 1 To 16
				For x = 1 To 16
					'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					If m_traceBuffer(i, x) = True Then
						'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.Col = i
						.Row = x
						.CellBackColor = System.Drawing.ColorTranslator.FromOle(RGB(red, green, blue))
					End If
				Next 
			Next 
			'.Redraw = True
			'.Refresh
        End With
        m_emuTraceBuffer_display = True
	End Function
	
	Public Function m_emuTraceBuffer_reset() As Object ' Reset the trace Buffer
		Dim i As Object
		Dim x As Byte
		For i = 1 To 16
			For x = 1 To 16
				'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				m_traceBuffer(i, x) = False
			Next 
		Next 
        Call Grid_ResetColours16x16((frmMain.Fuel))
        m_emuTraceBuffer_reset = True
	End Function
	
	Public Function Trace_Show(ByRef Grid As AxMSFlexGridLib.AxMSFlexGrid, ByRef offsets() As Integer, ByRef SetorReset As Boolean) As Object
		'##########################
		'######## LOOK AT THIS FUNCTION!!!! RE-make!
		Dim f_rpmColour As System.Drawing.Color
		Dim f_tpColour As System.Drawing.Color
		Dim f_normColour As System.Drawing.Color
		Dim f_loop As Short
		Dim f_gridRow As Short
		Dim f_gridCol As Short
		Dim f_gridRowSel As Short
		Dim f_gridColSel As Short
		Dim f_col As Short
		Dim f_row As Short
		
		f_gridRow = Grid.Row
		f_gridCol = Grid.Col
		f_gridRowSel = Grid.RowSel
		f_gridColSel = Grid.ColSel
		
		f_tpColour = System.Drawing.ColorTranslator.FromOle(RGB(255, 255, 60))
		f_rpmColour = System.Drawing.ColorTranslator.FromOle(RGB(0, 225, 255))
		f_normColour = System.Drawing.ColorTranslator.FromOle(&H8000000F)
		
		For f_loop = LBound(offsets) To UBound(offsets)
			f_row = (offsets(f_loop) \ (Grid.Cols - Grid.FixedCols)) + Grid.FixedRows
			f_col = (offsets(f_loop) Mod (Grid.Cols - Grid.FixedCols)) + Grid.FixedCols
			If f_row > Grid.rows - Grid.FixedRows Then
				f_row = Grid.rows - 1
			End If
			Grid.Row = 0
			Grid.Col = f_col
			If SetorReset Then
				Grid.BackColor = f_tpColour
			Else
				Grid.BackColor = f_normColour
			End If
			If m_sixTeenBit Then
				Grid.Col = f_col + 1
				If SetorReset Then
					Grid.BackColor = f_tpColour
				Else
					Grid.BackColor = f_normColour
				End If
			End If
			Grid.Col = 0
			Grid.Row = f_row
			If SetorReset Then
				Grid.BackColor = f_rpmColour
			Else
				Grid.BackColor = f_normColour
			End If
		Next 
		
		Grid.Row = f_gridRow
		Grid.Col = f_gridCol
		Grid.RowSel = f_gridRowSel
		Grid.ColSel = f_gridColSel
        Trace_Show = True
	End Function
	
	Public Function trace_show_rst() As Object
		Dim i As Byte
		For i = 1 To 16
			Row(i) = False
			Col(i) = False
        Next
        trace_show_rst = True
	End Function
	
	
	Public Function increment(ByRef Value_ As Byte, ByVal inc As Byte) As Object
        Value_ = Value_ + inc
        increment = True
	End Function
End Module